﻿//打开字滑入效果
window.onload = function(){
	$(".connect p").eq(0).animate({"left":"0%"}, 600);
	$(".connect p").eq(1).animate({"left":"0%"}, 400);
}; 
$(document).ready(function(){

        function GetRequest() {   
        var url = location.search; //获取url中"?"符后的字串   
        var theRequest = new Object();   
        if (url.indexOf("?") != -1) {   
           var str = url.substr(1);   
           strs = str.split("&");   
           for(var i = 0; i < strs.length; i ++) {   
              theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);   
           }   
        }   
            return theRequest;   
        }
        var shopId;
        var Request = new Object();
        Request = GetRequest();
        shopId = Request["shopId"];
        $("input[type=hidden]").attr("value",shopId);
        $("input[name='gender']").get(0).checked=true; 
        $("input:radio[name='gender']").change(function (){
            $("input:radio:not([checked])").prev("i").removeClass("checked").addClass("unchecked").attr("checked",'');
            $("input:radio:checked").prev("i").removeClass("unchecked").addClass("checked").attr("checked",'checked');
        });
	$("#registerForm").validate({
//            submitHandler : function(form) {
//            $(form).ajaxSubmit({
//                dataType:"json",
//                success:function( jsondata ){
//                    console.log(jsondata);
//                    if( jsondata.code == 200 ){
//                        window.location.href = "index.html";
//                    }else{
//                        alert("fail");
//                    }
//                  }
//                }); 
//                },
                focusInvalid : true,
		rules:{
			username:{
				required:true,
				minlength:2,
				maxlength:8
			},
			age:{
				required:true,
				minlength:1,
				maxlength:2
			},
			phone_number:{
				required:true,
				phone_number:true,
				digits:true
			}
		},
		//错误信息提示
		messages:{
			username:{
				required:"必须填写用户名",
				minlength:"用户名最少2个字哦",
				maxlength:"用户名也太长了吧"
			},
			age:{
				required:"年龄要填写哦",
				maxlength:"请输入正确的年龄"
			},
			phone_number:{
				required:"请输入手机号码",
				digits:"请输入正确的手机号码"
			}
		}
	});
	jQuery.validator.addMethod("phone_number", function(value, element) {
		var length = value.length; 
		var phone_number = /^1[34578]\d{9}$/ ;
		return this.optional(element) || (length == 11 && phone_number.test(value)); 
	}, "手机号码格式错误"); 
});
